Advances in Active Libraries and Generic Programming

نویسندگان

  • Jacob Nyffeler Smith
  • Jaakko Järvi
  • Gabriel Dos Reis
  • Thomas Ioerger
  • James Sacchettini
چکیده

Interpretation of Predicates In this section we give an example of the abstract interpretation of a predicate which has a conjunction. The predicate tests if the parameters S and R which both naturally carry the structure ordered set actually both carry the structure ring. The predicate is: 2The source of the code is found in the file “EXPR2.spad” in OpenAxiom [Ope09] 5.4. ABSTRACT INTERPRETATION OF CATEGORIES 59 R has Ring and S has Ring The abstract store Φ for at the program point for the predicate has the value: Φ = { 〈S has Ring 7→ 1/2〉, 〈R has Ring 7→ 1〉, ... } The evaluation of the predicate in Φ is: Φ(R has Ring and S has Ring) = Φ(R has Ring) andK Φ(R has Ring) = 1 andK 1/2 = 1/2 The abstract interpretation of the predicate is shown below: JR has Ring and S has RingK = JR has RingK t JS has RingK =  〈R has Ring 7→ 1〉, 〈R has Group 7→ 1〉, · · ·  t  〈S has Ring 7→ 1〉, 〈S has Group 7→ 1〉, · · ·  =  〈R has Ring 7→ 1〉, 〈R has Group 7→ 1〉, 〈S has Ring 7→ 1〉, 〈S has Group 7→ 1〉, · · ·  Implementation of hascat in the Prototype The implementation of “hascat” is a function that takes three arguments: the syntactic representation of a domain D, the syntactic representation of an instantiated category C, and the current abstract store Φ of the category being abstractly interpreted. The function uses the Spad domain Table(Key, Entry) (a mapping from keys Key to entries Entry), where the function: key?:(Key,Table(Key,Entry)) →Boolean is analogous to the function “find” from the operational semantics defined in Section 5.2.4. We thus implement hascat as: hascat(D, C, Φ) == 2 key?(MakeHasCat(‘%,C), Application(D, Rename(Proj(Φ, D)), args(D), parms(C))) First, we call the function Application for the domain D, which returns a Spad Table containing facts which are expressed in terms of the symbol ‘% about D. Then we build the representation of a has-predicate with a call to MakeHasCat over ‘% and C, and look for that predicate in the table. The function hascat then relies heavily on the implementation of the function Application, described in the next section. Implementation of Application. The function Application takes the representation of an instantiated category ICat and an abstract store Phi representing the assumptions passed from the calling program point. Pseudo-code based on our prototype is shown below. Application(ICat, Phi) == 2 arity0? ICat ⇒ interpret(getDef(name(ICat)), Phi) instCatDef := getDef(name(ICat)) 4 for idx in 1..#args(ICat) repeat 60 CHAPTER 5. LOCAL SPECIALIZATION Phi’ := Application(args(ICat).idx, Phi) 6 Phi’ := Rename(Phi’, ‘%, parms(instCatDef).idx) Phi := join(Phi, Phi’) 8 Phi’’ := interpret(instCatDef, Phi) for idx in 1..args(ICat) repeat 10 Phi’’ := Rename(Phi’, args(ICat).idx, parms(instCatDef).idx) 12 Phi’’ If the instantiated category is a constant, a variable, or functor with arity = 0 it is just re-interpreted directly, with the interpret function. If arity > 0, then each argument args(ICat).idx of the instantiated category is recursively re-interpreted by a call to Application. The result is an abstract store with facts in terms of “%” about the argument; all facts about “%” are renamed to be facts about the argument parms(instCatDef).idx. All the abstract stores of the arguments are joined together into an abstract store called Phi’. The abstract store Phi’ is then used as assumptions for the re-interpretation of the instantiated category ICat. The syntactic representation for the category ICat is instCatDef which is acquired by a call to the global repository of syntactic representations getDef using the name of the category name(ICat). The syntactic representation is then re-interpreted, giving a new set of facts Phi’’. The facts in Phi’’ are in terms of the names of the formal parameters of the instantiated category, and are renamed to be in terms of the names of the actual arguments.

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Generative Programming and Active Libraries

We describe generative programming, an approach to generating customized programming components or systems, and active libraries, which are based on this approach. In contrast to conventional libraries, active libraries may contain metaprograms that implement domain-specific code generation, optimizations, debugging, profiling and testing. Several working examples (Blitz++, GMCL, Xroma) are pre...

متن کامل

Usage of Generic Programming on Hackage

Generic programming language constructs, tools and libraries have been available in Haskell since the first report on the programming language Haskell. At the beginning of the 1990s generic programming techniques could be used via the deriving construct, and since then numerous generic programming libraries and tools have been developed. At the time of writing, the categories ‘generic’ and ‘gen...

متن کامل

Comparing Datatype Generic Libraries in Haskell

Datatype-generic programming is about defining functions that depend on the structure, or “shape”, of datatypes. It has been around for more than 10 years, and a lot of progress has been made, in particular in the lazy functional programming language Haskell. There are more than 10 proposals for generic programming libraries or language extensions for Haskell. In this paper we compare and chara...

متن کامل

Libraries for Generic Programming in Haskell

These lecture notes introduce libraries for datatype-generic programming in Haskell. We introduce three characteristic generic programming libraries: lightweight implementation of generics and dynamics, extensible and modular generics for the masses, and scrap your boilerplate. We show how to use them to use and write generic programs. In the case studies for the different libraries we introduc...

متن کامل

How To Lift a Library

Generic algebraic libraries run the risk of losing eeciency compared to non-generic libraries. To solve the seeming antagonism between genericity and eeciency, we propose a technique which we call lifting. The lifting process is an abstraction process which starts with a well-known eecient algorithm and abstracts carefully from it. As lifting guarantees that fast non-generic algorithms instanti...

متن کامل

A Generic Formal Metatheory Framework for First-Order Representations

This paper presents GMETA: a generic framework for first-order representations of variable binding that provides once and for all many of the so-called infrastructure lemmas and definitions required in mechanizations of formal metatheory. The framework employs datatype-generic programming and modular programming techniques to provide a universe representing a family of datatypes. This universe ...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2009